/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.servlet;

import br.com.foxline.model.Annex;
import br.com.foxline.service.AnnexService;
import java.io.IOException;
import java.io.OutputStream;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author roniere
 */
@WebServlet(name = "ViewImageServlet", urlPatterns = "/viewImage/*")
public class ViewImageServlet extends HttpServlet{
    
    @EJB
    AnnexService annexService;
    private static final long serialVersionUID = 201011231103L;

    public ViewImageServlet() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        OutputStream out = null;
        out = response.getOutputStream();
        
        try {
            String id = request.getParameter("annex");
            Annex annex = new Annex();
            
            if(id != null){
                annex = annexService.find(Long.parseLong(id));
                annexService.genReportAnnex(annex, request, response);
                
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
